import { aiWorkflowRules, getTemplateReules } from './templateValidateRules';
import { template } from './template/index';
// ignore 相关

// 下一步改变，忽略节点
const IgnoreChangeNextStepNode = [
	'messageSure',
	'ivvr',
	'speakWaiting',
	'detectLivingFace',
	'faceCompare',
	'messageCollect',
	'silentWating',
	'requestLocation',
	'scanCode',
	'sendMessage',
	'signContract',
	'idCardCompare',
	'sendForm',
	'optionJudge',
	'sendContents',
	'nlp',
	'soundReception',
	'variableJudge',
	'variableCollection',
	'sendDeposition',
	'sendSign',
	'inviteHumanThreeParties',
	'collectShortVideo',
	'interfaceCall',
	'startSystemRecording',
	'stopSystemRecording',
	'cardCollection',
	'llm'
];

/** 限定 number 类型输入框 */
const numberInputProperty = [
	'waitTime',
	'noAnswerTimesMax',
	'otherTimesMax',
	'confidence',
	'detectTimesMax',
	'wordsOverTime',
	'otherWaitTime',
	'noAnswerOverTime',
	'wordsTimesMax',
	'resultFailedTimesMax',
	'blurAnswers.0.wordsTimesMax',
	'repeatAnswers.0.wordsTimesMax',
	'llmRecognizeTimesMax'
];

/** 视图节点是否包含 AI 播报 */
const hasAiSpeak = [
	'messageSure',
	'variableCollection',
	'sendSign',
	'sendDeposition',
	'messageCollect',
	'faceCompare',
	'requestLocation',
	'scanCode',
	'sendForm',
	'idCardCompare',
	'collectShortVideo',
	'speakWaiting',
	'ivvr',
	'cardCollection',
	'llm'
];
/** 视图节点是否包含 接口请求URL  */
const hasRequestApi = ['interfaceCall'];

const hasConfidence = ['detectLivingFace', 'faceCompare', 'idCardCompare'];
const hasAiProcessSpeech = ['messageSure', 'ivvr'];
const hasWordsYes = [
	'messageSure',
	'variableCollection',
	'sendSign',
	'sendDeposition',
	'messageCollect',
	'detectLivingFace',
	'faceCompare',
	'requestLocation',
	'scanCode',
	'sendForm',
	'idCardCompare',
	'soundReception',
	'collectShortVideo',
	'inviteHumanThreeParties',
	'interfaceCall',
	'startSystemRecording',
	'stopSystemRecording',
	'cardCollection'
];
const hasNextStep = ['speakWaiting', 'sendMessage', 'silentWating', 'messageSummary', 'sendContents'];
const hasNextStepNo = [
	'messageSure',
	'variableCollection',
	'sendSign',
	'sendDeposition',
	'faceCompare',
	'idCardCompare',
	'requestLocation',
	'scanCode',
	'sendForm',
	'collectShortVideo',
	'inviteHumanThreeParties',
	'startSystemRecording',
	'stopSystemRecording',
	'cardCollection'
];
const hasWordsOther = [
	'messageSure',
	'variableCollection',
	'sendSign',
	'sendDeposition',
	'messageCollect',
	'detectLivingFace',
	'faceCompare',
	'requestLocation',
	'scanCode',
	'ivvr',
	'sendForm',
	'idCardCompare',
	'optionJudge',
	'soundReception',
	'variableJudge',
	'nlp',
	'collectShortVideo',
	'inviteHumanThreeParties',
	'interfaceCall',
	'cardCollection',
	'llm'
];
const hasWordsNoAnswer = ['messageSure', 'ivvr', 'inviteHumanThreeParties', 'llm'];
const hasAiSpeakTextArea = ['ivvr', 'speakWaiting'];
const hasWaitTime = [
	'messageSure',
	'speakWaiting',
	'variableCollection',
	'sendSign',
	'sendDeposition',
	'soundReception',
	'messageCollect',
	'requestLocation',
	'scanCode',
	'sendForm',
	'silentWating',
	'optionJudge',
	'nlp',
	'ivvr',
	'inviteHumanThreeParties',
	'interfaceCall',
	'cardCollection',
	'llm'
];
const hasEndTemplate = ['hangup', 'transfer', 'sceneTransfer'];
const hasWordsIntention = ['ivvr'];
const hasWordsVariableJudge = ['variableJudge'];
const hasWordsInterfaceSelect = ['sceneTransfer', 'sendForm', 'sendDeposition', 'collectShortVideo', 'inviteHumanThreeParties', 'interfaceCall', 'cardCollection'];
const hasWordsVariable = ['variableCollection'];
const hasOtherWaitTime = ['variableCollection', 'sendSign', 'sendDeposition', 'nlp', 'ivvr', 'scanCode', 'sendForm', 'requestLocation', 'collectShortVideo', 'cardCollection', 'llm'];
const hasNoAnswerOverTime = ['ivvr', 'llm'];
const hasCollectionResultSelect = ['soundReception', 'messageCollect'];
const hasBusinessInstruct = ['sendMessage'];
const hasMultipleSelect = ['messageSummary'];
const hasWordsOptionJudge = ['optionJudge'];
const hasWordsSendContents = ['sendContents'];
const hasNlpBranch = ['nlp'];
const hasSelectVideoIcon = [
	'messageSure',
	'messageCollect',
	'speakWaiting',
	'detectLivingFace',
	'faceCompare',
	'requestLocation',
	'scanCode',
	'ivvr',
	'sendForm',
	'idCardCompare',
	'sendSign',
	'sendDeposition',
	'variableCollection',
	'collectShortVideo',
	'cardCollection'
];
const hasRepeatWords = ['messageSure'];
const hasBlurWords = ['messageSure'];
const hasResultFailed = ['cardCollection'];
const hasRecognizeFailed = ['llm'];
const hasLLMIntentPoints = ['llm'];

const templateFormLabel = {
	messageSure: ['肯定回答', '否定回答', '其他回答', '不回答'],
	detectLivingFace: ['通过', '', '不通过'],
	faceCompare: ['通过', '不通过', '检测不到人脸'],
	hangup: [],
	messageCollect: ['有结果', '', '没结果'],
	requestLocation: ['获取成功', '获取失败', '等待超时'],
	scanCode: ['扫码成功', '扫码失败', '扫码超时'],
	sendMessage: [],
	signContract: [],
	speakWaiting: [],
	transfer: [],
	ivvr: ['', '', '其他回答', '不回答'],
	idCardCompare: ['通过', '不通过', '检测不到人脸'],
	sendForm: ['提交成功', '提交失败', '超时未提交'],
	waitingRead: '查阅等待',
	sceneTransfer: [],
	summaryConfirm: [],
	silentWating: [],
	optionJudge: ['', '', '其他选项'],
	messageSummary: [],
	sendContents: [],
	nlp: ['', '', '识别失败'],
	soundReception: ['有结果', '', '没结果'],
	variableJudge: ['', '', '其他分支'],
	sendSign: ['提交成功', '提交失败', '超时未提交'],
	sendDeposition: ['提交成功', '提交失败', '超时未提交'],
	variableCollection: ['提交成功', '提交失败', '超时未提交'],
	collectShortVideo: ['提交成功', '提交失败', '超时未提交'],
	inviteHumanThreeParties: ['邀请成功', '邀请超时', '邀请被拒', '邀请发送失败'],
	interfaceCall: ['调用成功', '', '调用失败'],
	startSystemRecording: ['成功', '失败', ''],
	stopSystemRecording: ['成功', '失败', ''],
	cardCollection: ['采集成功', '采集失败', '采集超时', '', '识别失败'],
	llm: ['', '', '其他回答', '不回答', '识别失败']
};

// 信息确认汇总可选节点
const messageSummaryNode = [
	'messageSure',
	'ivvr',
	'speakWaiting',
	'detectLivingFace',
	'faceCompare',
	'messageCollect',
	'silentWating',
	'requestLocation',
	'scanCode',
	'sendMessage',
	'signContract',
	'idCardCompare',
	'sendForm',
	'optionJudge',
	'sendContents',
	'nlp',
	'soundReception',
	'variableJudge',
	'sendDeposition',
	'sendSign',
	'variableCollection',
	'collectShortVideo',
	'interfaceCall',
	'inviteHumanThreeParties'
];

// 默认挂断模板话术
const hangup = { do: { data: { reason: 'quietly' }, command: 'hangup' } };

// 默认转人工模板
const transfer = {
	after: { command: 'receive-message' },
	answer: [
		{ do: { data: { reason: 'quietly' }, command: 'hangup' }, key: ['ok'] },
		{ do: { data: { reason: 'quietly' }, command: 'hangup' }, key: 'others' }
	],
	do: { data: { data: { cmd: 'transfer' }, type: 'peer-cmd' }, command: 'send-message' }
};

// 默认活体检测、人脸比对参数
const faceLivingAndCompare = { confidence: null, intervalMS: null, isRealTime: false, allowablePassRate: 0.3 };

// 默认全局配置单选框数据
const keyLabelOptions = [
	{
		id: 1,
		label: '是',
		value: 1
	},
	{
		id: 2,
		label: '否',
		value: 0
	}
];

// 机器人异常挂断下一步选项
const rebotExceptionOptions = [
	{
		id: 1,
		value: 'send-message',
		label: '转人工服务'
	},
	{
		id: 2,
		value: 'hangup',
		label: '挂断'
	}
];

// 收集结果数据类型列表 “文字串”、“数字串”和“数值”格式
const collectionResultList = [
	{ id: 1, label: '文字串', value: 'text' },
	{ id: 2, label: '数字串', value: 'numericString' },
	{ id: 3, label: '数值', value: 'numeric' }
];

// 卡证采集选项
const defaultCardCollectionOptions = [
	{ id: 1, label: '身份证', value: 'ID-card' },
	{ id: 2, label: '银行卡', value: 'bank-card' }
];

const TalkEnum = {
	HANG_UP: 'hangup',
	MESSAGE_SURE: 'messageSure',
	TRANSFER: 'transfer',
	SPEAK_WAITING: 'speakWaiting',
	FACE_COMPARE: 'faceCompare',
	ID_CARD_COMPARE: 'idCardCompare',
	MESSAGE_COLLECT: 'messageCollect',
	SCAN_CODE: 'scanCode',
	SEND_VIDEO: 'sendVideo',
	SEND_PAGE: 'sendPage',
	SCREEN_SNAP_SHOT: 'screenSnapshot',
	SEND_RICH_TEXT: 'sendRichText',
	SEND_PDF: 'sendPdf',
	SIGN_CONTRACT: 'signContract',
	REQUEST_LOCATUON: 'requestLocation',
	DETECT_LIVING_FACE: 'detectLivingFace',
	IVVR: 'ivvr',
	SEND_FORM: 'sendForm',
	WAITING_READ: 'waitingRead',
	SCENE_TRANSFER: 'sceneTransfer',
	SUMMARY_CONFIRM: 'summaryConfirm',
	SILENT_WATING: 'silentWating',
	OPTION_JUDGE: 'optionJudge',
	MESSAGE_SUMMARY: 'messageSummary',
	NLP: 'nlp',
	SOUND_RECEPTION: 'soundReception',
	VARIABLE_JUDGE: 'variableJudge',
	SEND_DEPOSITION: 'sendDeposition',
	SEND_SIGN: 'sendSign',
	VARIABLE_COLLECTION: 'variableCollection',
	INVITE_LABOR_TRIPARTITE: 'inviteHumanThreeParties',
	VIDEO_COLLECT: 'collectShortVideo',
	INTERFACE_CALL: 'interfaceCall',
	START_RECORDING: 'startSystemRecording',
	STOP_RECORDING: 'stopSystemRecording',
	CRAD_COLLECTION: 'cardCollection',
	LLM: 'llm'
};

const WorkflowNodeName = {
	BlankNode: '空白节点',
	detectLivingFace: '活体检测',
	faceCompare: '人脸比对',
	hangup: '结束模版',
	messageCollect: '信息记录',
	messageSure: '信息确认',
	requestLocation: '获取位置',
	scanCode: '推送扫码',
	sendMessage: '业务指令',
	signContract: '合同签署',
	speakWaiting: '播报话术',
	transfer: '转人工模板',
	ivvr: '业务导航',
	idCardCompare: '人证对比',
	sendForm: '表单填写',
	waitingRead: '查阅等待',
	sceneTransfer: '场景转接',
	summaryConfirm: '汇总确认',
	silentWating: '静默等待',
	optionJudge: '选项判断',
	messageSummary: '信息汇总',
	sendContents: '内容推送',
	nlp: 'NLP对接',
	soundReception: '收音模板',
	variableJudge: '变量判断',
	sendSign: '推送签名',
	sendDeposition: '证言抄录',
	variableCollection: '信息收集',
	inviteHumanThreeParties: '邀请人工三方',
	collectShortVideo: '短视频采集',
	interfaceCall: '接口调用',
	startSystemRecording: '开始双录',
	stopSystemRecording: '停止双录',
	cardCollection: '卡证采集',
	llm: 'LLM意图识别'
};

const templateValidateRules = (talkId, property, form) => {
	return getTemplateReules(talkId, property, form);
};

const baseTemplateTalk = {
	name: '', // 模板名称
	aiSpeak: null, // AI播报
	waitTime: null, // 等待时长
	wordsYes: null, // 肯定回答 AI 说
	nextStepYes: null, // 肯定回答下一步操作
	wordsNo: null, // 否定回答 AI 说
	nextStepNo: null, // 否定回答下一步
	wordsOther: null, // 其他回答 AI 说
	otherTimesMax: null, // 其他回答最大允许次数
	nextStepOther: null, // 其他回答下一步操作
	wordsEnd: null, // 其他回答下一步前 AI 说
	wordsNoAnswer: null, // 不回答 AI 说
	noAnswerTimesMax: null, // 不回答最大允许次数
	nextStepNoAnswer: null, // 不回答下一步操作
	wordsEndNoAnswer: null, // 不回答下一步前 AI 说
	aiProcessSpeech: null, // 智能问答 AI 说
	confidence: null, // 活体检测阈值
	detectTimesMax: null, // 活体检测次数
	wordsOverTime: null, // 超时等待时长
	otherWaitTime: null,
	noAnswerOverTime: null, // 不回答等待时长
	resultFailedNextStep: null, // 结果失败下一步
	resultFailedWaitTimes: null, // 识别失败等待时长
	resultFailedTimesMax: null, //  结果失败最大允许次数
	resultFailedSpeak: null, // 结果失败 AI 说
	resultFailedNextStepSpeak: null, // 结果失败 AI 说
	formId: null, // 推送表单ID
	bizSceneId: null, // 场景转接 ID
	bizSceneName: null, // 场景名称
	hangupReason: null, // 挂断原因
	transferReason: null, // 转人工原因
	transferGroups: [], // 转人工技能组
	isCompleted: false, // 是否办结
	resource: null, // 内容推送数据源
	testimonyId: null, //证言抄录ID
	informationRushurlAddress: null, // 信息汇总推送的URL
	intentLib: null, // 意图库
	repeatSetting: false, // 是否显示重复回答
	blurSetting: false, // 是否显示模糊回答
	blurAnswers: [
		{
			words: null,
			wordsVideo: null,
			wordsVariableId: null,
			wordsVariables: [],
			wordsVideoValidate: true,
			wordsEndVariableId: null,
			wordsEndVariables: [],
			wordsTimesMax: null,
			nextStep: null,
			wordsEnd: null,
			wordsEndVideo: null,
			wordsEndVideoValidate: true
		}
	], // 嗯啊模糊回答
	repeatAnswers: [
		{
			words: null,
			wordsVideo: null,
			wordsVariableId: null,
			wordsVariables: [],
			wordsVideoValidate: true,
			wordsEndVariableId: null,
			wordsEndVariables: [],
			wordsTimesMax: null,
			nextStep: null,
			wordsEnd: null,
			wordsEndVideo: null,
			wordsEndVideoValidate: true
		}
	], // 没听清,请重复

	typeOfCollectedResults: 'text', // 收集结果数据类型
	intelligentReply: {
		data: [],
		isOn: false,
		mainProcessSpeech: '',
		speechBeginWaitingTimeMS: 3000
	},
	summary: [], // 信息汇总
	notifyExternal: {
		method: 'post',
		params: [],
		url: null
	},
	wordsSendContents: {
		url: '', //推送网页的链接地址
		next: '', //下一步
		size: 0, //推送视频的大小
		fileName: '', //bpm确定保存之后的节点框<推送富文本:>文案，类似于其他模板的第一个Ai说
		originalname: '', //服务器返回的原视频地址名字
		fileList: [], //本地视频
		uploadUrl: '', //上传本地视频
		inputUrl: '', //推送视频地址输入框
		type: '', //选择的相关类型 ：send_video=推送视频，send_page=推送网页，send_richText=推送富文本
		isEdit: false, //Radio 单选框选择的相关业务类型默认隐藏，
		wordage: '', //推送富文本的内容
		textData: '', //富文本的内容1500个字
		wordsVariableId: '',
		wordsVariables: [],
		pdfList: [], //pdf
		uploadPdfUrl: '',
		id: '' // 业务资料ID
	}, // 内容推送数据源
	businessInstruct: {
		type: ''
	}, // 指令收集相关数据

	// NPL 肯定回答
	answerYesData: {
		keys: [],
		isAnswerNluLib: true,
		isOtherNluLib: false,
		nluMark: 'positive'
	},
	// NPL 否定回答
	answerNoData: {
		keys: [],
		isAnswerNluLib: true,
		isOtherNluLib: false,
		nluMark: 'negative'
	},
	// NPL 重复回答
	answerRepeatData: {
		keys: [],
		isAnswerNluLib: true,
		isOtherNluLib: false,
		nluMark: 'repeat'
	},
	// NPL 模糊回答
	answerFuzzyData: {
		keys: [],
		isAnswerNluLib: true,
		isOtherNluLib: false,
		nluMark: 'fuzzy'
	},
	// AI播报关联变量ID
	aiSpeakVariableId: null,
	// 智能问答 AI 回复 关联变量ID
	aiProcessSpeechVariableId: null,
	// 肯定回答 AI 说 关联变量ID
	wordsYesVariableId: null,
	// 否定回答 AI 说 关联变量ID
	wordsNoVariableId: null,
	// 其他回答 AI 说 关联变量ID
	wordsOtherVariableId: null,
	// 最大次数 AI 说 关联变量ID
	wordsEndVariableId: null,
	// 不回答 AI 说 关联变量ID
	wordsNoAnswerVariableId: null,
	// 最大次数 AI 说 关联变量ID
	wordsEndNoAnswerVariableId: null,
	// 变量内容
	aiSpeakVariables: [],
	aiProcessSpeechVariables: [],
	wordsYesVariables: [],
	wordsNoVariables: [],
	wordsOtherVariables: [],
	wordsEndVariables: [],
	wordsNoAnswerVariables: [],
	wordsEndNoAnswerVariables: [],
	resultFailedSpeakVariables: [],
	resultFailedNextStepSpeakVariables: [],
	// 关联变量数据
	associatedVariable: {
		id: '',
		name: '',
		describe: '',
		initMode: '',
		type: '',
		url: '',
		method: '',
		params: [],
		dataMasking: {}
	},
	wordsVariable: null, //收集的变量
	// 预录制视频属性
	aiSpeakVideo: null, // AI 播报视频属性
	wordsYesVideo: null, // 肯定回答 AI 说 视频属性
	wordsNoVideo: null, // 否定回答 AI 说 视频属性
	wordsOtherVideo: null, // 其他回答 AI 说 视频属性
	wordsEndVideo: null, // 其他回答下一步前 AI 说 视频属性
	wordsNoAnswerVideo: null, // 不回答 AI 说 视频属性
	wordsEndNoAnswerVideo: null, // 不回答下一步前 AI 说 视频属性
	resultFailedSpeakVideo: null,
	resultFailedNextStepSpeakVideo: null,
	llmRecognizeTimesMax: null, // llm意图识别识别失败，最大允许次数
	llmRecognizeNextStep: null, // llm意图识别失败，下一步
	ivvrOptionsVideo: [], // ivvr 动态添加视频选项

	// IVVR 动态 answer
	ivvrOptions: [],
	intentPoints: [], // 意图点
	// 选项判断 动态添加
	judgeOptions: [
		{ option: '', nextStepOption: '' },
		{ option: '', nextStepOption: '' }
	],

	// NLP 动态添加属性
	nlpOptions: [],

	// 变量判断动态添加内容
	variableJudgeOptions: [],

	// 添加视频按钮状态控制
	aiSpeakVideoValidate: true,
	wordsYesVideoValidate: true,
	wordsNoVideoValidate: true,
	wordsOtherVideoValidate: true,
	wordsEndVideoValidate: true,
	wordsNoAnswerVideoValidate: true,
	wordsEndNoAnswerVideoValidate: true, // 不回答下一步前 AI 说 视频属性
	resultFailedSpeakVideoValidate: true, // 识别结果失败
	resultFailedNextStepSpeakVideoValidate: true, // 识别结果失败

	// 短视频
	collectShortVideoTime: null, // 采集时长

	// 邀请三方
	agentName: null, // 人工坐席工号
	inviteMediaType: null, // 通话模式 audio | video
	microphoneStatus: null, // 麦克风状态 mute | unmute
	callMethod: 'post', // 调用方式：post、get、delete、put\
	groups: [], // 技能组
	inviteMode: 'none', // 邀请三方模式 none | agent | group
	//请求参数
	requestBody: [],
	// 返回参数
	responseBody: [],

	// 卡证收集类型
	cardCollectionType: '',

	// 卡证采集绑定项
	identifyResult: [],
	// 是否开启 OCR
	openOCR: false
};

const generateTalk = () => {
	return baseTemplateTalk;
};

/** 流程节点数据 */
const talks = template;

/**
 * 获取工作流节点数据
 * @param {TalkEnum} talk
 * @returns { object }
 */

const getTalks = talk => {
	if (talks[talk]) {
		return talks[talk];
	}
	return null;
};

const AITalk = {
	hangup,
	transfer,
	hasEndTemplate,
	hasAiSpeak,
	hasWaitTime,
	hasWordsYes,
	hasNextStep,
	hasNextStepNo,
	hasConfidence,
	hasWordsOther,
	hasWordsNoAnswer,
	hasAiProcessSpeech,
	hasAiSpeakTextArea,
	numberInputProperty,
	hasWordsIntention,
	hasWordsVariableJudge,
	hasWordsInterfaceSelect,
	hasWordsVariable,
	hasOtherWaitTime,
	hasNoAnswerOverTime,
	hasCollectionResultSelect,
	hasBusinessInstruct,
	hasMultipleSelect,
	hasWordsOptionJudge,
	hasWordsSendContents,
	hasNlpBranch,
	hasSelectVideoIcon,
	hasRepeatWords,
	getTalks,
	generateTalk,
	templateValidateRules,
	hasBlurWords,
	TalkEnum,
	aiWorkflowRules,
	WorkflowNodeName,
	collectionResultList,
	faceLivingAndCompare,
	keyLabelOptions,
	rebotExceptionOptions,
	templateFormLabel,
	messageSummaryNode,
	IgnoreChangeNextStepNode,
	hasRequestApi,
	defaultCardCollectionOptions,
	hasResultFailed,
	hasLLMIntentPoints,
	hasRecognizeFailed
};

export default AITalk;
